/**
 * Created by 叶子 on 2017/7/30.
 */
import * as type from "./type";
import * as category from "./category";
import * as http from "../axios/index";

const requestData = category => ({
    type: type.REQUEST_DATA,
    category
});
export const receiveData = (data, category) => ({
    type: type.RECEIVE_DATA,
    data,
    category
});
/**
 * 请求数据调用方法
 * @param funcName      请求接口的函数名
 * @param params        请求接口的参数
 */
export const fetchData = ({funcName, params, stateName}) => dispatch => {
    !stateName && (stateName = funcName);
    dispatch(requestData(stateName));
    return http[funcName](params).then(res => dispatch(receiveData(res, stateName)));
};

export const updateMenu = (data) => {
    return {
        type: 'UPDATEMENU',
        menuState: data
    }
}

export const updateSingleRate = (data) => {
    return {
        type: 'UPDATE_RATE_DATA',
        rateData: data
    }
}

export const updateMember = (data) => {
    return {
        type: type.UPDATE_MEMBER_INFO,
        category: category.MEMBER_INFO,
        [category.MEMBER_INFO]: data
    }
}
